<?php
namespace app\admin\behavior;
use app\admin\model\User as UserModel;
use think\Controller;
class CheckLogin extends Controller{
	
	public function run(){
		$id = cookie('uid');
		
		if($id){
			$user = UserModel::where('id',$id)->find();
			if($user && (request()->action() == 'login' || request()->action() == 'register'))
				$this->redirect('/');
			else if(!$user)
				$this->redirect('/login');
			else if(request()->action() == 'logout') 
				return;
		}else{
			if(request()->action() != 'login' && request()->action() != 'register')
				$this->redirect('/login');
		}
	}
}